package slm.games.tris;

 
 
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;


public class TrisGamePreferences extends PreferenceActivity implements OnSharedPreferenceChangeListener
{
	static final String TAG = "TrisGamePreferences";
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(TAG, "Creating TrisGamePreferences");
		//mNotifier = new AutoAnswerNotifier(this);
		//mNotifier.updateNotification();
		SharedPreferences sharedPreferences =  PreferenceManager.getDefaultSharedPreferences(this);
		sharedPreferences.registerOnSharedPreferenceChangeListener(this);
		addPreferencesFromResource(R.xml.preferences);
		updateModePreferenceLabels(sharedPreferences);
		 
        
	}
	
	private void updateModePreferenceLabels(SharedPreferences sharedPreferences)
	{
		ListPreference gameModeListPreference = (ListPreference) findPreference("game_mode");
		gameModeListPreference.setSummary(gameModeListPreference.getEntry());
		
		EditTextPreference editTextPreference = (EditTextPreference) findPreference("edit_player_name");
		if ( editTextPreference!=null && editTextPreference.getText()!=null && !editTextPreference.getText().equals(""))
			editTextPreference.setSummary(editTextPreference.getText());
		else
			editTextPreference.setSummary(getString(R.string.player_name_summary));
	}

	
	@Override
	public void onSharedPreferenceChanged(SharedPreferences arg0, String arg1) {
		 updateModePreferenceLabels(arg0);
	}
	
	@Override
	protected void onDestroy() {
		getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
		super.onDestroy();
	}
	}
